package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.AccountCoupons;
import com.fantastic.service.zjs.AccountCouponsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 09:15
 * @description: 用户优惠券关联表请求控制器
 */
@RestController
@RequestMapping("/accountCoupons")
public class AccountCouponsControllerAdmin {

    @Resource
    private AccountCouponsService accountCouponsService;

    /**
     * 查询用户优惠券关联信息
     *
     * @param accountCoupons
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listAccountCoupons")
    public ResultData listAccountCoupons(AccountCoupons accountCoupons,
                                         @RequestParam(name = "page",
                                                 defaultValue = "1") int pageNum,
                                         @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AccountCoupons> accountCouponsList = accountCouponsService.listAccountCoupons(accountCoupons);
        PageInfo<AccountCoupons> accountCouponsPageInfo = new PageInfo<>(accountCouponsList);
        return new ResultData(RespStatusInfo.OK, accountCouponsPageInfo);
    }

    /**
     * 查询单个用户优惠券关联信息
     *
     * @return
     */
    @GetMapping("/getAccountCoupons")
    public ResultData getAccountCoupons(Integer accountId) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.getAccountCoupons(accountId));
    }

    /**
     * 添加用户优惠券关联信息
     *
     * @param accountCoupons
     * @return
     */
    @PostMapping("/insertAccountCoupons")
    public ResultData insertAccountCoupons(AccountCoupons accountCoupons) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.insertAccountCoupons(accountCoupons));
    }

    /**
     * 账号通过积分兑换优惠券
     *
     * @param accountId        账号id
     * @param couponId         优惠卷id
     * @param integralExchange 所需要的积分
     * @param integralId       积分商品的id
     * @param integralSell     兑换的数量
     * @return
     */
    @PostMapping("/creditsExchange")
    public ResultData creditsExchange(Integer accountId, Integer couponId, Integer integralExchange,
                                      Integer integralId, Integer integralSell) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.creditsExchange(accountId, couponId,
                integralExchange, integralId, integralSell));
    }

    /**
     * 删除用户优惠券关联信息
     *
     * @param accountId
     * @param couponId
     * @return
     */
    @PostMapping("/deleteAccountCoupons")
    public ResultData deleteAccountCoupons(Integer accountId, Integer couponId) {
        return new ResultData(RespStatusInfo.OK, accountCouponsService.deleteAccountCoupons(accountId, couponId));
    }

}
